function stringEmpty(inputstring) {
    if ((inputstring == null) || (inputstring == "")) {
        return true;
    }
    return false;
}

function checkemail(obj) {
    if (obj) {
        tst = /^[A-Z]([A-Z0-9_.-])*@([A-Z0-9-]+\.)*[A-Z0-9]([A-Z0-9-]+\.)([A-Z]{2,6})$/i;
        if (!tst.test(obj.value) && (obj.value != '')) {
            alert (obj.name + " is niet geldig");
            obj.focus();
            return false;
        }
    }
    return true;
}

function checkemailwithoutalert(obj) {
    if (obj) {
        tst = /^[A-Z]([A-Z0-9_.-])*@([A-Z0-9-]+\.)*[A-Z0-9]([A-Z0-9-]+\.)([A-Z]{2,6})$/i;
        if (!tst.test(obj.value) && (obj.value != '')) {
            return false;
        }
    }
    return true;
}

function RequiredStandardForm(formName) {
    if (document.forms[formName].verplicht) {
	    strVerplicht = document.forms[formName].verplicht.value;
	    var Listname = strVerplicht.replace(/\s/g,'');
	    var arListname = Listname.split(",");
	    return Required(arListname, formName);
    } else {
        return true;
    }
}

function MakeFieldNameReadable( lEl ) {
  var strReturn;
  if ( lEl.getAttribute( 'alt' ) ) {
    strReturn = lEl.alt;
  } else {
    strReturn = lEl.name
    while ( strReturn.indexOf( "_" ) > 0 ) {
      strReturn = strReturn.replace( "_", " " );
    }
  }
  return strReturn;
}

function Required(listname, strFormName) {
    var foutmelding = "";

    for (var i = 0; i < listname.length; i++) {
        if (document.forms[strFormName].elements[listname[i]].options) {
            if (document.forms[strFormName].elements[listname[i]].value == '') {
                if (foutmelding == "") {
                    document.forms[strFormName].elements[listname[i]].focus();
                }
                foutmelding = foutmelding + "\n- " + MakeFieldNameReadable(document.forms[strFormName].elements[listname[i]]);
            }
        } else {
            if (document.forms[strFormName].elements[listname[i]].length > 0) {
                var bChecked = false;
                for (var j = 0; j < document.forms[strFormName].elements[listname[i]].length; j++) {
                    if (document.forms[strFormName].elements[listname[i]][j].checked) {
                        bChecked = true;
                    }
                }
                if (bChecked == false) {
                    if (foutmelding == "") {
                        document.forms[strFormName].elements[listname[i]][0].focus();
                    }
                    foutmelding = foutmelding + "\n- " + MakeFieldNameReadable(document.forms[strFormName].elements[listname[i]][0]);
                }
            } else {
                if (stringEmpty(document.forms[strFormName].elements[listname[i]].value)) {
                    if (foutmelding == "") {
                        document.forms[strFormName].elements[listname[i]].focus();
                    }
                    foutmelding = foutmelding + "\n- " + MakeFieldNameReadable(document.forms[strFormName].elements[listname[i]]);
                } else {
                    if (document.forms[strFormName].elements[listname[i]].onchange) {
                        var onch = "" + document.forms[strFormName].elements[listname[i]].onchange;
                        if (onch.indexOf("checkemail",0) > 1) {
                            if (!checkemailwithoutalert(document.forms[strFormName].elements[listname[i]])) {
                                if (foutmelding == "") {
                                    document.forms[strFormName].elements[listname[i]].focus();
                                }
                                foutmelding = foutmelding + "\n- " + MakeFieldNameReadable(document.forms[strFormName].elements[listname[i]]) + " is niet geldig";
                            }
                        }
                    }
                }
            }
        }
    }
    if (foutmelding != "") {
        foutmelding = "U hebt de volgende velden niet correct ingevuld:" + foutmelding;
        alert (foutmelding);
        return false;
    }
    return true;
}